package com.yijianonghu.service.wxwebsite.products;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yijianonghu.dal.model.ProAccessHistory;
import com.yijianonghu.dal.model.ProAccessHistoryExample;
import com.yijianonghu.dal.model.SysBlog;
import com.yijianonghu.dal.model.SysBlogExample;
import com.yijianonghu.util.DBUtils;

import net.javahub.dao.BaseSqlDao;
import net.javahub.dao.BaseSqlDao.SqlWrapper;
import net.javahub.dao.IBaseDao;
import net.javahub.service.BaseTransactionalService;

@Service
public class ProductDetailService extends BaseProductDetailService{

//	@Autowired
//	private BaseSqlDao baseSqlDao;
//		
//	@Autowired
//	private IBaseDao<ProAccessHistory, Integer, ProAccessHistoryExample> proAccessHistoryDao;
//	
//	//商品详情
//	public List<Map<String, Object>> getProductDetail(Integer productId, Integer userId) throws Exception{
//		//基本信息
//		String sql="select c.qq,c.nickname,c.avatar,c.address,c.mobile,c.starscore as farmer_starscore,c.replycount as farmer_replycount,mt.* from sys_blog mt,sys_client c where mt.id=#{params.productId} and mt.client_id=c.id and mt.removeflag=0";
//		SqlWrapper wrapper=new SqlWrapper();
//		wrapper.setSqlStatement(sql);
//		wrapper.addParam("productId", productId);
//		List<Map<String, Object>> resultList=baseSqlDao.select(wrapper);
//		List<Map<String,Object>> tempList=null;
//		if(resultList!=null && (!resultList.isEmpty())){
//			//商品属性信息
//			sql="select * from pro_blog_attribute where blog_id=#{params.productId}";
//			wrapper.setSqlStatement(sql);
////			tempList=baseSqlDao.select(wrapper);
////			resultList.get(0).put("attributeItems", (tempList==null || tempList.isEmpty())?"":tempList);
//			addToResult(wrapper, "attributeItems", resultList);
//			//组装图片信息
//			Object imgCountObj=resultList.get(0).get("imgcount");
//			if(imgCountObj!=null){
//				Integer imgCount=DBUtils.parseToNumber(Integer.class, imgCountObj);
//				if(imgCount!=null && imgCount>0){
//					sql="select * from sys_img where keytype=2 and keyid=#{params.productId}";
//					wrapper.setSqlStatement(sql);
////					tempList=baseSqlDao.select(wrapper);
////					resultList.get(0).put("imgItems", (tempList==null || tempList.isEmpty())?"":tempList);
//					addToResult(wrapper, "imgItems", resultList);
//				}
//			}
//			//收藏 - 商品详情UI中没有收藏。
////	        $sqlstr="select count(*) from sys_love where keytype=2 and client_id=$client_id and keyid='$id'";
////	        $temp_array[0]['collectflag'] = $this->get_one_bysql($sqlstr);
////			sql="select count(*) from sys_love where keytype=2 and client_id=#{params.clientId} and keyid=#{params.productId}";
////			wrapper.addParam("clientId", value);
//			
//			//点赞 - 商品详情中没有点赞。
////			$sqlstr="select count(*) from sys_love where client_id='$client_id' and keytype=3 and keyid=".$id;
////	        $temp_array[0]['goodflag']=$this->get_one_bysql($sqlstr);
//			
//			//访问记录？
////	        $keytype=$temp_array[0]['type'];
////	        if ($keytype != 0 && $keytype != 1)
////	        {
////	            $keyid=$id;
////
////	            $sqlstr="select id from pro_access_history where client_id='$client_id' and keytype=$keytype and keyid='$keyid'";
////	            $acc_hist_id=$this->get_one_bysql($sqlstr);
////	            if (empty($acc_hist_id))
////	            {
////	                $sqlstr="insert into pro_access_history set client_id='$client_id',keytype=$keytype,keyid='$keyid',regdate='". sys_get_time() ."'";
////	                $result=$this->do_execute($sqlstr);
////	            }
////	            else
////	            {
////	                $sqlstr="update pro_access_history set regdate='". sys_get_time() ."' where id='$acc_hist_id'";
////	                //echo $sqlstr;
////	                $result=$this->do_execute($sqlstr);
////	            }
////	        }
//			Byte keytype=DBUtils.parseToNumber(Byte.class,resultList.get(0).get("type"));
//			if(keytype != 0 && keytype !=1 ){
//				ProAccessHistoryExample proAccessHistoryExample=new ProAccessHistoryExample();
//				proAccessHistoryExample.createCriteria()
//					.andClientIdIsNotNull()
//					.andClientIdEqualTo(userId)
//					.andKeytypeIsNotNull()
//					.andKeytypeEqualTo(keytype)
//					.andKeyidIsNotNull()
//					.andKeyidEqualTo(productId);
//				List<ProAccessHistory> proAccessHistoryList=proAccessHistoryDao.selectByExample(ProAccessHistory.class, proAccessHistoryExample);
//				ProAccessHistory proAccessHistory=null;
//				if(proAccessHistoryList==null || proAccessHistoryList.isEmpty()){
//					proAccessHistory=new ProAccessHistory();
//					proAccessHistory.setClientId(userId);
//					proAccessHistory.setKeytype(keytype);
//					proAccessHistory.setKeyid(productId);
//					proAccessHistory.setRegdate(new Date());
//					proAccessHistoryDao.insert(proAccessHistory);
//				} else {
//					proAccessHistory=proAccessHistoryList.get(0);
//					proAccessHistory.setRegdate(new Date());
//					proAccessHistoryDao.updateByPrimaryKey(proAccessHistory);
//				}
//			}
//		}
//		
//		return resultList;
//	}
//	
//	private void addToResult(SqlWrapper wrapper, String key, List<Map<String, Object>> resultList){
//		List<Map<String, Object>> tempList=baseSqlDao.select(wrapper);
//		resultList.get(0).put(key, (tempList==null || tempList.isEmpty())?"":tempList);
//	}
}
